

#include <bits/stdc++.h>
using namespace std;

int x,y;
int ans;
void sc(int x,int y)
{
	
	if (x < y)
	{
		while(x < y)
		{
			x *= 5;
			ans++;
		}
		while (x > y && x % 6 == 0)
		{
			x /= 6;
			ans++;
		} 
	}
	else 
	{
		while(x > y && x%6==0)
		{
			x /= 6;
			ans++;
		}
		while (x < y)
		{
			x *= 5;
			ans++;
		}
	}
	
	if(x == y)  cout << ans << endl;
	else cout << -1 << endl;
}


int main()
{
	int t;
	cin >> t;
	while(t--)
	{
		cin >> x >> y;
		sc(x,y);
		ans = 0;
	}
	return 0;
}

